const jwt = require('jsonwebtoken');

// JWT密钥和过期时间配置
const JWT_ACCESS_SECRET = 'zeno-access-secret-key';
const ACCESS_TOKEN_EXPIRES = '15m';

/**
 * 生成访问令牌（短期有效）
 */
const generateAccessToken = (userId) => jwt.sign({ id: userId }, JWT_ACCESS_SECRET, { expiresIn: ACCESS_TOKEN_EXPIRES });

/**
 * 校验访问令牌
 */
const verifyAccessToken = (token) => {
  try {
    return jwt.verify(token, JWT_ACCESS_SECRET);
  } catch {
    return null;
  }
};

module.exports = { generateAccessToken, verifyAccessToken }; 